package cn.csc.module.pay.controller.admin.funddetailslog;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.math.BigInteger;
import java.util.*;
import java.io.IOException;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.common.pojo.CommonResult;
import static cn.csc.framework.common.pojo.CommonResult.success;

import cn.csc.framework.excel.core.util.ExcelUtils;

import cn.csc.framework.operatelog.core.annotations.OperateLog;
import static cn.csc.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.csc.module.pay.controller.admin.funddetailslog.vo.*;
import cn.csc.module.pay.dal.dataobject.funddetailslog.PayFundDetailsLogDO;
import cn.csc.module.pay.convert.funddetailslog.PayFundDetailsLogConvert;
import cn.csc.module.pay.service.funddetailslog.PayFundDetailsLogService;

@Api(tags = "管理后台 - 用户资金收支明细表记录")
@RestController
@RequestMapping("/pay/fund-details-log")
@Validated
public class PayFundDetailsLogController {

    @Resource
    private PayFundDetailsLogService fundDetailsLogService;

    @PostMapping("/create")
    @ApiOperation("创建用户资金收支明细表记录")
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:create')")
    public CommonResult<BigInteger> createFundDetailsLog(@Valid @RequestBody PayFundDetailsLogCreateReqVO createReqVO) {
        return success(fundDetailsLogService.createFundDetailsLog(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新用户资金收支明细表记录")
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:update')")
    public CommonResult<Boolean> updateFundDetailsLog(@Valid @RequestBody PayFundDetailsLogUpdateReqVO updateReqVO) {
        fundDetailsLogService.updateFundDetailsLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除用户资金收支明细表记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = BigInteger.class)
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:delete')")
    public CommonResult<Boolean> deleteFundDetailsLog(@RequestParam("id") BigInteger id) {
        fundDetailsLogService.deleteFundDetailsLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得用户资金收支明细表记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = BigInteger.class)
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:query')")
    public CommonResult<PayFundDetailsLogRespVO> getFundDetailsLog(@RequestParam("id") BigInteger id) {
        PayFundDetailsLogDO fundDetailsLog = fundDetailsLogService.getFundDetailsLog(id);
        return success(PayFundDetailsLogConvert.INSTANCE.convert(fundDetailsLog));
    }

    @GetMapping("/list")
    @ApiOperation("获得用户资金收支明细表记录列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:query')")
    public CommonResult<List<PayFundDetailsLogRespVO>> getFundDetailsLogList(@RequestParam("ids") Collection<BigInteger> ids) {
        List<PayFundDetailsLogDO> list = fundDetailsLogService.getFundDetailsLogList(ids);
        return success(PayFundDetailsLogConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得用户资金收支明细表记录分页")
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:query')")
    public CommonResult<PageResult<PayFundDetailsLogRespVO>> getFundDetailsLogPage(@Valid PayFundDetailsLogPageReqVO pageVO) {
        PageResult<PayFundDetailsLogDO> pageResult = fundDetailsLogService.getFundDetailsLogPage(pageVO);
        return success(PayFundDetailsLogConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出用户资金收支明细表记录 Excel")
    @PreAuthorize("@ss.hasPermission('pay:fund-details-log:export')")
    @OperateLog(type = EXPORT)
    public void exportFundDetailsLogExcel(@Valid PayFundDetailsLogExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<PayFundDetailsLogDO> list = fundDetailsLogService.getFundDetailsLogList(exportReqVO);
        // 导出 Excel
        List<PayFundDetailsLogExcelVO> datas = PayFundDetailsLogConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "用户资金收支明细表记录.xls", "数据", PayFundDetailsLogExcelVO.class, datas);
    }

}
